package matlap.client.view.student;

import java.util.Iterator;
import java.util.List;

import matlap.client.services.deadline.DeadlineService;
import matlap.client.services.deadline.DeadlineServiceAsync;
import matlap.shared.Deadline;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class DeadlinesComposite extends Composite{

	DeadlineServiceAsync c1 = GWT.create(DeadlineService.class);
	private VerticalPanel vp;
	private Grid g;

	public DeadlinesComposite(){
		init();

		c1.getDeadlinesNumber(new AsyncCallback<Integer>() {

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Gond van volume");

			}

			@Override
			public void onSuccess(Integer result) {
				g.resize(result+1,2);
			}			
		});

		c1.getDeadlines(new AsyncCallback<List<Deadline>>() {

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Gond van people");

			}

			@Override
			public void onSuccess(List<Deadline> result) {
				int i =1;
				Iterator<Deadline> it = result.iterator();
				while (it.hasNext()){
					Deadline distr = (Deadline) it.next();

					
					g.setText(i, 1, distr.getDeadline());
					i++;


				}


			}

		});
	}

	private void init() {
		vp = new VerticalPanel();
		initWidget(vp);
		vp.setSize("670px", "108px");

		g = new Grid(11,2);
		
		Label lb0 = new Label("Lapsz\u00E1m");
		lb0.setStyleName("Header");
		g.setWidget(0,0,lb0);
		
		Label lb1 = new Label("Hat\u00E1ridő");
		lb1.setStyleName("Header");
		g.setWidget(0,1,lb1);

		
		g.setText(1,0,"Szeptember");
		g.setText(2,0,"Okt\u00F3ber");
		g.setText(3,0,"November");
		g.setText(4,0,"December");
		g.setText(5,0,"Janu\u00E1r");
		g.setText(6,0,"Febru\u00E1r");
		g.setText(7,0,"M\u00E1rcius");
		g.setText(8,0,"\u00C1prilis");
		g.setText(9,0,"M\u00E1jus");
		g.setText(10,0,"J\u00FAnius");
		g.setBorderWidth(2);
		vp.add(g);
		g.setSize("489px", "34px");

	}

}
